
const mainObj = {
    toTop: {
        init () {
            let topRef = document.querySelector('.to-top')
            const backTop = () => {
                const cubic = value => Math.pow(value, 3)
                const easeInOutCubic = value => value < 0.5
                ? cubic(value * 2) / 2
                : 1 - cubic((1 - value) * 2) / 2
                const el = document.body
                const beginTime = Date.now()
                const beginValue = el.scrollTop
                const rAF = window.requestAnimationFrame || (func => setTimeout(func, 16))
                console.log(el,'123');
                const frameFunc = () => {
                    const progress = (Date.now() - beginTime) / 500
                    if (progress < 1) {
                        el.scrollTop = beginValue * (1 - easeInOutCubic(progress))
                        rAF(frameFunc)
                    } else {
                        el.scrollTop = 0
                    }
                };
                rAF(frameFunc)
            }
            const handleScroll = () => {
                if (document.body.scrollTop > 100) {
                    topRef.style.display = 'block'
                } else {
                    topRef.style.display = 'none'
                }
            }
            topRef && (topRef.onclick = () => {
                backTop()
            })
            handleScroll()
            window.addEventListener('scroll', handleScroll)
        }
    }
}